//
//  HJRepairTurnCarCell.m
//  GAMCAfterSales
//
//  Created by 贺佳 on 2018/5/15.
//  Copyright © 2018年 glendale. All rights reserved.
//

#import "HJRepairTurnCarCell.h"

@interface HJRepairTurnCarCell()
//保存在本地的顾问数据匹配
/**
 本地顾问数据
 顾问的字典
 */
@property(nonatomic,strong)NSMutableDictionary*serviceCodeDict;
//保存在本地的维修分类数据匹配
/**
 本地维修分类数据
 维修分类的字典
 */
@property(nonatomic,strong)NSMutableDictionary*repairTypeCodeDict;
@end
@implementation HJRepairTurnCarCell
-(NSMutableDictionary *)repairTypeCodeDict
{
    if (!_repairTypeCodeDict) {
        _repairTypeCodeDict=[NSMutableDictionary dictionary];
        NSArray*ary=[self readershuDICimform][@"TM_REPAIR_TYPE_MAIN"];
        _repairTypeCodeDict=[NSMutableDictionary dictionary];
        for (NSDictionary*dict in ary) {
            _repairTypeCodeDict[dict[@"CODE"]]=dict[@"NAME"];
        }
    }
    return _repairTypeCodeDict;
}
-(NSMutableDictionary *)serviceCodeDict
{
    if (!_serviceCodeDict) {
        NSArray*ary=[self readershuDICimform][@"SERVICE_ADVISOR"];
        _serviceCodeDict=[NSMutableDictionary dictionary];
        for (NSDictionary*dict in ary) {
            _serviceCodeDict[dict[@"CODE"]]=dict[@"NAME"];
        }
    }
    return _serviceCodeDict;
}

UITablecellM(@"HJRepairTurnCarCell")
-(void)setUI{

    self.selectionStyle=UITableViewCellSelectionStyleNone;
//    WEAKSELF;
    self.selectionStyle=UITableViewCellSelectionStyleNone;
    for (int i=0; i<7; i++) {
        UILabel *titlelabel = [[UILabel alloc]init];
        titlelabel.backgroundColor = [UIColor clearColor];
        titlelabel.textColor = [UIColor grayColor];
        titlelabel.numberOfLines=0;
        titlelabel.font = [UIFont fontWithName:@"ArialMT" size:14];
        [titlelabel setTextAlignment:NSTextAlignmentCenter];
        [self.contentView addSubview:titlelabel];
        titlelabel.userInteractionEnabled=YES;
        if (i==6) {
            UIButton*btn=[[UIButton alloc]init];
            btn.backgroundColor=[UIColor redColor];
            [btn setTitle:@"交车" forState:UIControlStateNormal];
            [btn setTitle:@"已交车" forState:UIControlStateDisabled];
            [btn addTarget:self action:@selector(clickSubmitCar) forControlEvents:UIControlEventTouchUpInside];
            [titlelabel addSubview:btn];
            btn.titleLabel.font=HJFont(14);
            btn.layer.cornerRadius=3;
            btn.layer.masksToBounds=YES;
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(50, 30));
                make.center.mas_equalTo(titlelabel);
            }];
        }
    }
}
-(void)setRepairTurnCarModel:(HJRepairTurnCarModel *)repairTurnCarModel
{
    _repairTurnCarModel=repairTurnCarModel;
    int i=0;
    for (UILabel*label in self.contentView.subviews) {
        switch (i) {
            case 0:
                label.text=repairTurnCarModel.ROWNUM;
                break;
            case 1:
                label.text=repairTurnCarModel.RO_NO;
                break;
            case 2:
                label.text=self.repairTypeCodeDict[repairTurnCarModel.REPAIR_TYPE_CODE];
                break;
            case 3:
                label.text=repairTurnCarModel.LICENSE;
                break;
            case 4:
                label.text=self.serviceCodeDict[repairTurnCarModel.SERVICE_ADVISOR];
                break;
            case 5:
                label.text=repairTurnCarModel.DELIVERER;
                break;
                
            default:
                break;
        }
        i++;
    }
}
-(void)clickSubmitCar{
    if ([_delegate respondsToSelector:@selector(repairTurnCarCell:submitCar:)]) {
        [_delegate repairTurnCarCell:self submitCar:self.repairTurnCarModel];
    }
}
-(void)setIndexPath:(NSIndexPath *)indexPath
{
    _indexPath=indexPath;
    UILabel*label=self.contentView.subviews[0];
    label.text=[NSString stringWithFormat:@"%zd",indexPath.row+1];
    
}
-(NSMutableDictionary *)readershuDICimform
{
    NSMutableDictionary *dic=[NSMutableDictionary dictionary];
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path=[paths objectAtIndex:0];
    NSString *str=[path stringByAppendingPathComponent:@"Dic.text"];
    dic=[NSMutableDictionary dictionaryWithContentsOfFile:str];
    //nslog(@"%@",dic);
    return dic;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat w=self.contentView.mj_w/self.contentView.subviews.count;
    int i=0;
    for (UIView*subView in self.contentView.subviews) {
        subView.frame=CGRectMake(i*w, 0, w, self.contentView.mj_h);
        i++;
    }
}
@end
